package com.beiing.tianshuai.tianshuai.service;

import android.content.Context;

import com.beiing.tianshuai.tianshuai.entity.UserInfoBean;
import com.beiing.tianshuai.tianshuai.util.LogUtils;

import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.service.JPushMessageReceiver;

import static com.beiing.tianshuai.tianshuai.app.AppConstant.MSG_SET_ALIAS;

/**
 * 极光推送消息接受者
 *
 * @author Jinda Yang
 * @date 2018/6/5
 */

public class MyJPushMessageReceiver extends JPushMessageReceiver {

    private static final String TAG = "MyJPushMessageReceiver";

    @Override
    public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
        super.onTagOperatorResult(context, jPushMessage);
        int errorCode = jPushMessage.getErrorCode();
        switch (errorCode) {
            case 0:
                LogUtils.d("极光推送别名设置成功", TAG);
            case 6001:
                LogUtils.e("极光推送别名设置失败", TAG);
                break;
            case 6002:
                LogUtils.e("极光推送别名设置超时", TAG);
                JPushInterface.setAlias(context, MSG_SET_ALIAS, UserInfoBean.getUid(context));
                break;
            default:
                LogUtils.e("极光推送别名设置失败 错误代码：" + errorCode, TAG);
                break;
        }
    }
}